import React, { Component } from 'react'

export default class Child extends Component {
  constructor(){
    super();
    console.log('child constructor')
    this.state={
      time:new Date().toLocaleTimeString()
    }
  }
  render() {
    console.log('child render')
    return (
      <div>
        时间:{this.state.time}
    <h1>这是子组件: {this.props.num}-{this.state.num}</h1>
      </div>
    )
  }

 static getDerivedStateFromProps(props){
    console.log('getDerivedStateFromProps',props)
    return {
      ...props
    };
  }

  componentDidMount(){
    console.log('child componentDidMount')
    // this.timer = setInterval(() => {
    //   this.setState({
    //     time:new Date().toLocaleTimeString()
    //   })
    // }, 1000);
  }

  componentDidUpdate(){
    console.log('child componentDidUpdate')
  }

  componentWillUnmount(){
    console.log('child componentWillUnmount ')
    // clearInterval(this.timer)
  }
}
